<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * 扩展原有的分页类
 * @author wb_wenjie.wuwj <wb_wenjie.wuwj@alibaba-inc.com>
 * @copyright 2013-1-31 yahoo
 */
class MY_Pagination extends CI_Pagination
{
	function __construct($params = array())
	{
		parent::__construct($params);
	}
	
	/**
	 * 获取查询内容的偏移量和查询的条数
	 * @return array
	 */
	function get_limit_data()
	{
		$limit = array('limit_from' => 0, 'limit_end' => $this->per_page);
		if ($this->cur_page == 0)
		{
			return $limit;
		}
		$limit['limit_from'] = ($this->cur_page - 1) * $this->per_page;
		$limit['limit_end']  = $this->per_page;
		return $limit;
	}
	
	function initialize($params = array())
	{
		$this->CI =& get_instance();
		$attribute = array (
			
				'base_url',
				'prefix',
				'suffix',
				'total_rows',
				'per_page',
				'num_links',
				'cur_page',
				'use_page_numbers',
				'first_link',
				'next_link',
				'prev_link',
				'last_link',
				'uri_segment',
				'full_tag_open',
				'full_tag_close',
				'first_tag_open',
				'first_tag_close',
				'last_tag_open',
				'last_tag_close',
				'first_url',
				'cur_tag_open',
				'cur_tag_close',
				'next_tag_open',
				'next_tag_close',
				'prev_tag_open',
				'prev_tag_close',
				'num_tag_open',
				'num_tag_close',
				'page_query_string',
				'query_string_segment',
				'display_pages',
				'anchor_class' 
		);
		foreach ($attribute as $key)
		{
			$this->$key = (isset($params[$key])) ? $params[$key] : $this->CI->config->item($key);
		}
	}
}
/* End of file MY_Pagination.php */
/* Location: ./application/controllers/MY_Pagination.php */